package com.pudding.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.pudding.common.GenderEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author Pudding
 * @Date 2025/3/20 11:28
 */
@Slf4j
public class GenderConverter implements Converter<Integer> {

    /**
     * 这里读的时候会调用
     */
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 获取读取到的字符串
        String gender = cellData.getStringValue();
        log.info("读取到性别为：{}", gender);
        // 转化为对应的code枚举数字
        return GenderEnum.getCodeByLabel(gender);
    }
}
